package com.maliankeji.mybatisflexdemo;

import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.audit.MessageCollector;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;

import java.util.Scanner;

@SpringBootApplication
public class MybatisFlexDemoApplication {

    private static final Logger LOGGER = LoggerFactory.getLogger(MybatisFlexDemoApplication.class);

    public static void main(String[] args) {
        init();
        SpringApplication.run(MybatisFlexDemoApplication.class, args);
    }

    public static void init (){
        //开启审计功能
        AuditManager.setAuditEnable(true);
        //设置 SQL 审计收集器
        //MessageCollector collector = new ConsoleMessageCollector();
        //AuditManager.setMessageCollector(collector);
        AuditManager.setMessageCollector(auditMessage -> {
            LOGGER.info("SQL语句:{}, SQL耗时:{}ms", auditMessage.getFullSql(), auditMessage.getElapsedTime());
        });

        try(Scanner scanner = new Scanner(System.in)){

        }

    }

}
